home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ Oct 89 / Z0126-Re Object Casting…-Oct89 < prev    next >
Encoding:
Text File  |  1989-10-20  |  1.3 KB  |  46 lines  |  [TEXT/GEOL]

  1. Item    8207938                         18-Oct-89        11:22
  2.  
  3. From:   MUYSVASOVIC1                    ER&D - J-D Muys-Vasovic
  4.  
  5. To:     D0220                           American Zettler, Dirk Tjossen,PRT
  6.  
  7. cc:     MACAPP.TECH$                    MACAPP Tech
  8.  
  9. Sub:    Re: Object Casting…
  10.  
  11. Dirk,
  12.  
  13. TSortedList.Compare is declared as:
  14.  
  15. FUNCTION TSortedList.Compare(item1, item2: TObject): INTEGER;
  16.  
  17. Actually, the objects you are going to store in your sorted list are of a given
  18. class, say TFoo, declared as:
  19.  
  20. TYPE
  21.     TFoo = OBJECT(TObject)
  22.         fBar: INTEGER;
  23.         <many fields and methods>
  24.     END;
  25.  
  26. Now, your TSortedList.Compare (which must be overriden BTW), may be implemented
  27. as:
  28.  
  29. FUNCTION TSortedList.Compare(item1, item2: TObject): INTEGER; OVERRIDE;
  30. BEGIN
  31. IF item1.fBar < item2.fBar THEN Compare := kALessThanB
  32. ELSE IF item1.fBar > item2.fBar THEN Compare := kAGreaterThanB
  33. ELSE Compare := kAEqualB;
  34. END;
  35.  
  36. But this won't work: the pascal compiler will give you the "no such field in
  37. this object" error message: all references to item1 and item2 must first be
  38. typecasted to TFoo. Now, the statement according to which "item1 and item2 must
  39. be casted from type TObject to their actual type" is maybe a bit too strong,
  40. but you won't be able to compare them in any useful way if you don't.
  41.  
  42. Hope that answers your question.
  43.  
  44. Jean-Denis.
  45.  
  46.